package org.up.cs.oomgert.sparks;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.tmatesoft.svn.core.SVNAuthenticationException;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.auth.SVNAuthentication;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

public class App {

    private static Logger logger = Logger.getLogger(App.class);

    public static void main(String[] args) {
        PropertyConfigurator.configure("log4j.properties");
        logger.info("start App");
        String realm = "http://oomgert.googlecode.com:443";
        String projectUrl = "http://oomgert.googlecode.com/svn/";
        String username = "walters.simbaw";
        String password = "zr7rk8RS5Aa3";
        SVNRepository repository = null;
        try {
            DAVRepositoryFactory.setup();
            SVNURL url = SVNURL.parseURIDecoded(projectUrl);
            repository = SVNRepositoryFactory.create(url, null);
            ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password);
            repository.setAuthenticationManager(authManager);
            logger.info("Latest revision: " + repository.getLatestRevision());
            SVNAuthentication authenthication = authManager.getFirstAuthentication(ISVNAuthenticationManager.PASSWORD,
                    realm, url);
            logger.info("Username: " + authenthication.getUserName());
            logger.info("Kind: " + authenthication.getKind());
            logger.info("Protocol: " + authenthication.getURL().getProtocol());
        } catch (SVNAuthenticationException ex) {
            Logger.getLogger(App.class).error(ex);
        } catch (SVNException ex) {
            ex.printStackTrace();
        }
    }
}
